import axios from 'axios'
import { Toast } from 'vant'

const service = axios.create({
	baseURL: '/api'
})

service.interceptors.request.use(
	config => {
		// 自定义

		return config
	}
)

service.interceptors.response.use(
	response => {
		response.data = response.data.result

		return response
	},
	error => {
		// 自定义
		Toast({
			icon: 'close',
			type: 'fail',
			message: error.message,
			duration: 3000
		})
		return Promise.reject(error)
	}
)

export default service
